import React from "react";
import ReactDOM from "react-dom";
import { HashRouter as Router } from "react-router-dom"; // 路由
import { renderRoutes } from "react-router-config"; //  配置静态路由的一个工具库

import { Provider } from "react-redux";

import { ConfigProvider } from "antd";
import zhCN from "antd/es/locale/zh_CN";
import http from "@/utils/http"; // 封装 http 请求
import routes from "@/routes";
import "@/style/index.scss";

// 将 Saga 与 Redux Store 建立连接
import configureStore from "@/store";
import rootSaga from "@/store/sagas";

const store = configureStore();
rootSaga.map((saga) => store.runSaga(saga));

// 将http挂在的全局下，页面中就可以直接去引用，使用：$http['get'|'post'|...]
React.$http = http;

ReactDOM.render(
  <Provider store={store}>
    <ConfigProvider locale={zhCN}>
      {/*
       为了确保使用matchRoutes在render外部进行匹配以及在render内部进行匹配在同一分支中进行，必须在组件内部使用renderRoutes而不是<Route> 
       renderRoutes(routes)会把routers作为props传入到组件中
       */}
      <Router>{renderRoutes(routes)}</Router>
    </ConfigProvider>
  </Provider>,
  document.getElementById("root")
);
